<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>人力资源绩效评估管理</title>
<%@ include file="../../common/Style.jsp"%>
<script>

var dataGrid ;
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	var params = $.serializeObject($('#userForm'));
	dataGrid = $('#dataGrid').datagrid({
	
		url : 'hrEvalJSON!selectUserInfos',
		fit : true,
		border : false,
		queryParams: params,
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:false,
		nowrap : false,
		singleSelect:false,
		rownumbers : true,
		sortName : '',
		sortOrder : 'asc',
		rowStyler: function(index,row){
			var style = "";
			if (row.status == 1)
				style += 'color:red;';

			return style;
		},
		columns : [ [
 		    {
				field : 'user_id',
				title : '账号',
				checkbox:false,
				
				width : 45
			},{	
				field : 'user_name',
				title : '客户名字',
				width : 180,
				sortable:true,
				order:'desc'
			},{	
				field : 'roleType',
				title : '角色',
				width : 150			
			},{			    
				field : 'department',
				title : '部门',
				width : 80
				
		    }, {
				field : 'mobilePhone',
				title : '电话',
				width : 110,
				align: 'center'
		    },{
				field : 'resign',
				title : '状态',
				width : 80,			
				align: 'center',				
				formatter: function (value, row, index){
					if (row.resign == 0 )
						return "正常";
					else if (row.resign == 1 )
						return "离职";
				}
			},{				
				field : 'action',
				title : '重置密码',
				width : 70,
				align: 'center',
			formatter : function(value, row, index) {
				var str = '';

					str += $.formatString('<a href="#" onclick="resetPassWord(\'{0}\');"><img border="0" src="{1}" /></a>', row.user_id, '<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/reset.png');
								
				return str;
			}
		},{				
			field : 'action1',
			title : '一键登录',
			width : 70,
			align: 'center',
		formatter : function(value, row, index) {
			var str = '';

				str += $.formatString('<a href="#" onclick="oneKeyLogin(\'{0}\',\'{1}\');"><img border="0" src="{2}" /></a>', row.user_name,row.password, '<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/oneKeyLogin.png');
							
			return str;
		}
	} ,{				
				field : 'action2',
				title : '编辑',
				width : 70,
				align: 'center',
			formatter : function(value, row, index) {
				var str = '';

					str += $.formatString('<a href="#" onclick="updateUser(\'{0}\');"><img border="0" src="{1}" /></a>', row.user_id, '<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/update.png');
								
				return str;
			}
		}]],
		toolbar : '#toolbar',
	});

});

function selectUserInfo(){
	dataGrid.datagrid('load', $.serializeObject($('#userForm')));
}


function addUser(){
	var params = "UserInfor.user_id=" + 0;
	$.modalDialog({
		title : "新增员工信息",
		width : 480,
		height : 340,
		modal : false,
		draggable:false,
		href : 'hrEvalJSP!preEditUser?' + params,
		
	});
}

function updateUser(id){
	var params = "UserInfor.user_id=" + id;
	$.modalDialog({
		title : "更新员工信息",
		width : 480,
		height : 340,
		modal : false,
		draggable:false,
		href : 'hrEvalJSP!preEditUser?' + params,
		
	});
}


function resetPassWord(userId){
	var params = "userInfor.user_id="+userId
	$.post("hrEvalJSON!resetPassWord",params, resetBKProcess,"json");	

}

function resetBKProcess(data){
	var returnCode = data.returnCode;
	if (returnCode != SUCCESS)
		$.messager.alert('失败信息', data.message,'error');
	else {
		$.messager.alert('提示', data.message,'info');		
		$("#dataGrid").datagrid('reload');
	}		
}

function oneKeyLogin(userName,password){
    var params=  "user.user_name="+userName+"&user.password="+password;
    $.post("<%=request.getContextPath()%>/action/loginJSON!login",params, loginBackProcess,"json");
}
function loginBackProcess(data){
	var response = data.response;
	var returnCode = response.returnCode;
	if (returnCode != SUCCESS){
		$.messager.alert('错误提示',response.message,'warning');
	} else {
		var returnValue = response.returnValue;
		if (returnValue == 2){
		    window.location.href = "<%=request.getContextPath()%>/action/login!myTask";
		} else if (returnValue == 1)
			window.location.href = "<%=request.getContextPath()%>/action/userJSP!swithToChain";	
		else 
			$.messager.alert('错误提示',"无法找到对应链接",'warning');		    
	}
}

</script>
</head>
<body>
<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'north',border:false" style="height: 95px;">
	<s:form id="userForm" name="userForm"
		theme="simple" method="POST">
		<table width="98%" align="center" class="OuterTable">
			<tr>
				<td>
					<table width="100%" border="0">
						<tr>
							<td height="31" colspan="7">
								<table width="100%" border="0">
									<tr class="PBAOuterTableTitale">
										<td height="31" colspan="7">总部员工:									
										</td>
									</tr>
									<tr >
										<td width="6%"></td>
										<td width="3%"><strong>部门:</strong></td>
										<td width="14%">
											<s:select cssClass="easyui-combobox" style="width:150px" name="userInfor.department"  id="department" listKey="key" listValue="value" headerKey="0" headerValue="全部" list="#{'01':'会计部','02':'销售部','03':'物流部','04':'运营部','05':'商品部'}" ></s:select>
										</td>
										<td width="3%"><strong>角色：</strong></td>
										<td width="14%">
											<s:select cssClass="easyui-combobox" style="width:150px"  name="userInfor.roleType"  id="roleType" listKey="chainRoleTypeId" listValue="chainRoleTypeName" headerKey="-1" headerValue="全部角色" list="roles" ></s:select>
										</td>
										<td width="3%"><strong>状态:</strong></td>
										<td >
											<s:select cssClass="easyui-combobox" style="width:150px" name="userInfor.resign"  id="status" listKey="key" listValue="value" headerKey="0" headerValue="正常" list="#{'1':'离职'}" ></s:select>
										</td>
										
									</tr>
								
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</s:form>
	</div>
	
	<div data-options="region:'center',border:false">
		<table id="dataGrid">
		</table>
			<div id="toolbar" style="display: none;">
				<a onclick="selectUserInfo();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-search',plain:true">查询</a> 
				<a onclick="addUser();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-add',plain:true">新增员工</a> 
			</div>
			 
		</div>
</div>
</body>
</html>